<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人项目管理系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
            <div class="container">
                <a class="navbar-brand" href="#">个人项目管理系统</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav me-auto">
                        <li class="nav-item">
                            <a class="nav-link active" href="#">首页</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">项目管理</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">用户管理</a>
                        </li>
                    </ul>
                    <div class="d-flex">
                        <span class="navbar-text me-3">欢迎，{{ currentUser.userName || '用户' }}</span>
                        <button class="btn btn-outline-light btn-sm" @click="logout">退出</button>
                    </div>
                </div>
            </div>
        </nav>

        <div class="container mt-4">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2>我的项目</h2>
                <button class="btn btn-primary" @click="showCreateProjectModal">新建项目</button>
            </div>

            <div class="row">
                <div class="col-md-4 mb-4" v-for="project in projects" :key="project.id">
                    <div class="card h-100">
                        <div class="card-body">
                            <h5 class="card-title">{{ project.projectName }}</h5>
                            <h6 class="card-subtitle mb-2 text-muted">
                                <span class="badge" :class="getProjectTypeBadgeClass(project.projectType)">{{ getProjectTypeText(project.projectType) }}</span>
                                <span class="badge bg-info ms-2">{{ getLanguageTypeText(project.languageType) }}</span>
                                <span class="badge" :class="getStatusBadgeClass(project.projectStatus)">{{ getStatusText(project.projectStatus) }}</span>
                            </h6>
                            <p class="card-text">{{ project.projectDesc || '暂无描述' }}</p>
                        </div>
                        <div class="card-footer d-flex justify-content-between">
                            <small class="text-muted">创建时间: {{ formatDate(project.createdAt) }}</small>
                            <div>
                                <button class="btn btn-sm btn-outline-primary me-2" @click="editProject(project)">编辑</button>
                                <button class="btn btn-sm btn-outline-danger" @click="deleteProject(project.id)">删除</button>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 无项目提示 -->
                <div class="col-12 text-center py-5" v-if="projects.length === 0">
                    <div class="empty-state">
                        <i class="bi bi-folder-plus display-1 text-muted"></i>
                        <h4 class="mt-3">暂无项目</h4>
                        <p class="text-muted">点击"新建项目"按钮创建您的第一个项目</p>
                        <button class="btn btn-primary mt-3" @click="showCreateProjectModal">新建项目</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 新建项目弹窗 -->
        <div class="modal fade" id="createProjectModal" tabindex="-1" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">新建项目</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <form @submit.prevent="createProject">
                            <div class="mb-3">
                                <label for="projectName" class="form-label">项目名称</label>
                                <input type="text" class="form-control" id="projectName" v-model="newProject.projectName" required>
                            </div>
                            <div class="mb-3">
                                <label for="projectDesc" class="form-label">项目描述</label>
                                <textarea class="form-control" id="projectDesc" rows="3" v-model="newProject.projectDesc"></textarea>
                            </div>
                            <div class="mb-3">
                                <label for="projectType" class="form-label">项目类型</label>
                                <select class="form-select" id="projectType" v-model="newProject.projectType" required>
                                    <option value="">请选择项目类型</option>
                                    <option value="PERSONAL">个人项目</option>
                                    <option value="COMPANY">公司项目</option>
                                    <option value="OPEN_SOURCE">开源项目</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label for="languageType" class="form-label">技术分类</label>
                                <select class="form-select" id="languageType" v-model="newProject.languageType" required>
                                    <option value="">请选择技术分类</option>
                                    <option value="JAVA">Java</option>
                                    <option value="KOTLIN">Kotlin</option>
                                    <option value="PYTHON">Python</option>
                                    <option value="REACT">React</option>
                                    <option value="ANDROID">Android</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label for="projectStatus" class="form-label">项目状态</label>
                                <select class="form-select" id="projectStatus" v-model="newProject.projectStatus" required>
                                    <option value="">请选择项目状态</option>
                                    <option value="DEVELOPING">开发中</option>
                                    <option value="COMPLETED">已完成</option>
                                    <option value="ABANDONED">已废弃</option>
                                </select>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" @click="createProject" :disabled="isSubmitting">
                            <span class="spinner-border spinner-border-sm me-1" v-if="isSubmitting"></span>
                            确定
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@3.2.36/dist/vue.global.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script src="js/app.js"></script>
</body>
</html>
